<template>
	<view class="goods_detail_container">
		<!--轮播图区域-->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in goods_info.pics" :key="index">
				<image :src="item.pics_big" class="swiper-item-img" @click="preview(index)"></image>
			</swiper-item>
		</swiper>
		
		<!--商品信息区域-->
		<view class="goods-info-box">
			<view class="goods-price">
				￥{{goods_info.goods_price}}
			</view>
			<view class="goods-info-body">
				<view class="goods_name">{{goods_info.goods_name}}</view>
				<view class="favi">
					<uni-icons type="star" size="18" color="gray"></uni-icons>
					<text>收藏</text>
				</view>
			</view>
			<view class="yf">快递：免运费</view>
		</view>
		
		<!-- 商品详情信息 -->
		<rich-text :nodes="goods_info.goods_introduce"></rich-text>
		
		<!--底部导航-->
		<view class="goods_nav">
			<uni-goods-nav :fill="true" :options="options" 
			:buttonGroup="buttonGroup" @click="onclick" @buttonClick="buttonClick"></uni-goods-nav>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods_info:{},
				//左侧按钮组的配置对象
				options:[
					{
						icon:'shop',
						text:'店铺'
					},
					{
						icon:'cart',
						text:'购物车',
						info:2
					}
				],
				//右侧按钮组的配置对象
				buttonGroup:[
					{
						text:'加入购物车',
						backgroundColor:'#ff0000',
						color:'#fff'
					},
					{
						text:'立即购买',
						backgroundColor:'#ffa200',
						color:'#fff'
					}
				
				]
			};
		},
		onLoad(options) {
			this.getGoodsInfo(options.goods_id)
		},
		methods:{
			//获取商品详细信息
			async getGoodsInfo(goods_id){
				const res =  await uni.$http.get('/api/public/v1/goods/detail',{goods_id})

				if(res.statusCode != 200){
					return uni.showMsg()
				}
				
				this.goods_info = res.data.message
			},
			//点击图片获取大图
			preview(index){
				uni.previewImage({
					index:index,
					urls:this.goods_info.pics.map(item => item.pics_big)
				})
			},
			//跳转到购物车
			onclick(e){
				if(e.content.text === '购物车'){
					uni.switchTab({
						url:'/pages/cart/cart'
					})
				}
			},
			//
			buttonClick(){}
		},

	}
</script>

<style lang="scss">
swiper{
	height: 750rpx;
}

.swiper-item-img{
	width: 100%;
	height: 100%;
}

.goods-info-box{
	padding: 10px;
	padding-right: 0;
	
	.goods-price{
		color: #C00000;
		font-size: 18px;
		margin: 10px 0;
	}
	.goods-info-body{
		display: flex;
		justify-content: space-between;
		.goods_name{
			font-size: 13px;
			margin-right: 10px;
		}
		.favi{
			width: 120px;
			font-size: 12px;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border-left: 1px solid #efefef;
			color: gray;
		}
	}
	.yf{
		font-size: 12px;
		color: gray;
		margin: 10px 0;
	}
}

.goods_nav{
	position: fixed;
	bottom: 0;
	left: 0;
	width: 100%;
}

.goods_detail_container{
	padding-bottom: 50px;
}

</style>
